package com.feng.controller;

import com.feng.pojo.Student;
import com.feng.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/student")
public class StudentController {

    @Autowired
    private StudentService studentService;

    @GetMapping("/{id}")
    public Student getStudentById(@PathVariable int id) {
        return studentService.selectStudentById(id);
    }

    @GetMapping("/name/{name}")
    public List<Student> getStudentByName(@PathVariable String name) {
        return studentService.selectStudentByName(name);
    }

    @GetMapping("/")
    public List<Student> getAllStudents() {
        return studentService.selectAllStudent();
    }

    @PostMapping("/")
    public int addStudent(@RequestBody Student student) {
        return studentService.insertStudent(student);
    }

    @PutMapping("/")
    public int updateStudent(@RequestBody Student student) {
        return studentService.updateStudent(student);
    }

    @DeleteMapping("/{id}")
    public int deleteStudent(@PathVariable int id) {
        return studentService.deleteStudentById(id);
    }

    @GetMapping("/ask")
    public String ask() {
        return "huangqian is beautiful girl";
    }

    @GetMapping("/answer")
    public String answer() {
        return "xiangzhi is a nice girl";
    }

}
